<cfsilent><!---

CF_Kalendar

COPYRIGHT & LICENSING INFO
-------------------------------------------------------------------

Copyright 2006 TJ Downes - tdownes@sanative.net - http://www.sanative.net

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

--->

<!--- attributes.view - defines which display mode to show: day, week, weeklist, month, condensed --->
<cfparam name="Attributes.view" type="string" default="list" />
<!--- attributes.rsCategories - a recordset of categories to populate the category select box --->
<cfparam name="attributes.categoriesRS" type="query" />
<!--- attributes.categoryID - defines which category to pull in our recordset --->
<cfparam name="attributes.categoryID" type="numeric" default="0" />
<!--- attributes.linkDate - defines the starting date of our recordset --->
<cfparam name="Attributes.linkDate" type="date" default="#Now()#" />
<!--- attributes.eventRecords - an array of structs containing the recordset --->
<cfparam name="Attributes.eventRecords" type="array" default="0" />
<!--- attributes.ExcludeTimeHeader - boolean to specifiy if the header on the calendar for times is displayed --->
<cfparam name="Attributes.ExcludeTimeHeader" type="boolean" default="no" />
<!--- attributes.TooltipSubLength - the length to concatenate the Title string for the tooltips --->
<cfparam name="Attributes.TooltipSubLength" type="string" default="35" />
<!--- attributes.maxDescriptionSize - the length to concatenate the Description string for the tooltips --->
<cfparam name="Attributes.maxDescriptionSize" type="numeric" default="150" />
<!--- attributes.calendarLinkPage - the page that the user is taken to when they click an event --->
<cfparam name="Attributes.calendarLinkPage" type="string" default="" />
<!--- attributes.urlAddString - a URL string to add to the calendarLinkPage attribute --->
<cfparam name="Attributes.urlAddString" type="string" default="" />

<!--- set week variables to establish start and end of week --->
<cfset DayOfWeek = -DayOfWeek(Attributes.linkDate) + 1 />
<cfset FirstDateOfWeek = CreateODBCDate(DateAdd('d', DayOfWeek, Attributes.linkDate)) />
<cfset LastDateOfWeek = CreateODBCDate(DateAdd('d', 7, FirstDateOfWeek)) />
<cfset eventRecords = Attributes.eventRecords />
</cfsilent>
<!--- WEEK NAV--->
<!--- display our top navigation --->
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table class="calendarNavTable" id="navbartop">
<tr>
		<td class="calendarNav">
		<cfform method=post action="#cgi.SCRIPT_NAME#" id="weekSelector" class="allForms">
		<div><input type="hidden" name="view" value="week" />
		<input type="hidden" name="categoryID" value="<cfoutput>#attributes.categoryID#</cfoutput>" />
		<select name="LinkDate" class="calendarSelectBoxes" onchange="changeWeek();">
			<cfloop index="LoopCount" from="-10" to="10">
			<cfset OptionWeek = DateAdd('ww', LoopCount, FirstDateOfWeek)>
			<cfif NOT LoopCount>
			<option selected="selected"><cfoutput>#DateFormat(FirstDateOfWeek, 'mmmm d, yyyy')#</cfoutput></option>
			<cfelse>
			<option><cfoutput>#DateFormat(OptionWeek, 'mmmm d, yyyy')#</cfoutput></option></cfif></cfloop>
		</select></div></cfform></td>
		<td class="calendarNav" style="text-align: center;">
		<cfif Week(Now()) neq Week(Attributes.LinkDate)>
		<cfform action="#cgi.SCRIPT_NAME#" method="post" id="viewweek" class="allForms">
		<div><input type="hidden" name="LinkDate" value="<cfoutput>#DateFormat(Now(), 'mmmm d, yyyy')#</cfoutput>" id="Link3Date" />
		<input type="hidden" name="categoryID" value="<cfoutput>#attributes.categoryID#</cfoutput>" />
		<input type="hidden" name="view" value="week" />
		<input type="submit" name="submit" value=" current week " class="calendarButtons" /></div></cfform>
		</cfif></td>
		<td class="calendarNav" style="text-align: right;">
		<cfform method="post" action="#cgi.SCRIPT_NAME#" id="viewchange" class="allForms">
		<div><input type="hidden" name="LinkDate" value="<cfoutput>#attributes.LinkDate#</cfoutput>" id="LinkDate" />
		<input type="hidden" name="categoryID" value="<cfoutput>#attributes.categoryID#</cfoutput>" />
		<select name="view" class="calendarSelectBoxes" onchange="document.getElementById('viewchange').submit();">
			<option value="day">day</option>
			<option value="week" selected="selected">week</option>
			<option value="weeklist">week list</option>
			<option value="month">month</option>
			<option value="list">condensed</option>
		</select></div></cfform></td>
		<td class="calendarNav" style="text-align: right;">
		<cfform method="post" action="#cgi.script_name#" id="categoryChange" class="allForms">
		<div><input type="hidden" name="linkdate" value="<cfoutput>#attributes.linkdate#</cfoutput>" id="linkdate" />
		<input type="hidden" name="view" value="<cfoutput>#attributes.view#</cfoutput>" />
		<select name="categoryID" class="calendarSelectBoxes" onchange="document.getElementById('categoryChange').submit();">
			<cfoutput query="attributes.categoriesRS">
			<option value="#categoryID#"<cfif attributes.categoryID eq categoryID> selected</cfif>>#left(categoryName, 25)#</option>
			</cfoutput>
			<option value="0"<cfif attributes.categoryID eq 0> selected</cfif>>all</option>	
		</select></div></cfform></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<!--- WEEK CALENDAR --->
<cfoutput>
<table class="calendarTable">
<tr>
	<td class="eventDayName">Sun</td>
	<td class="eventDayName">Mon</td>
	<td class="eventDayName">Tue</td>
	<td class="eventDayName">Wed</td>
	<td class="eventDayName">Thu</td>
	<td class="eventDayName">Fri</td>
	<td class="eventDayName">Sat</td>
</tr>
<tr>
	<td class="eventDayHeader">#DateFormat(FirstDateOfWeek, 'm/d/yy')#</td>
	<td class="eventDayHeader">#DateFormat(DateAdd('d', 1, FirstDateOfWeek), 'm/d/yy')#</td>
	<td class="eventDayHeader">#DateFormat(DateAdd('d', 2, FirstDateOfWeek), 'm/d/yy')#</td>
	<td class="eventDayHeader">#DateFormat(DateAdd('d', 3, FirstDateOfWeek), 'm/d/yy')#</td>
	<td class="eventDayHeader">#DateFormat(DateAdd('d', 4, FirstDateOfWeek), 'm/d/yy')#</td>
	<td class="eventDayHeader">#DateFormat(DateAdd('d', 5, FirstDateOfWeek), 'm/d/yy')#</td>
	<td class="eventDayHeader">#DateFormat(DateAdd('d', 6, FirstDateOfWeek), 'm/d/yy')#</td>
</tr>
</cfoutput>
<!--- Output week --->
<tr>
<cfloop index="LoopIndex" from="0" to="6">
	<cfset thisDay = DateAdd('d', LoopIndex, FirstDateOfWeek) />
	<td class="eventDay">
	<cfloop index="i" from="1" to="#ArrayLen(attributes.eventRecords)#">
	<cfoutput>
	<cfif CreateODBCDate(eventRecords[i].StartDate) lte CreateODBCDate(DateAdd('d', LoopIndex, FirstDateOfWeek))>
	<cfif CreateODBCDate(eventRecords[i].EndDate) gte CreateODBCDate(DateAdd('d', LoopIndex, FirstDateOfWeek))>
	<div class="eventdiv">
	<div class="timeHeader<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate> spandays</cfif>">
	<cfif len(trim(eventRecords[i].StartTime))>
	<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate>
		<cfif eventRecords[i].StartDate eq thisDay>
			#DateFormat(eventRecords[i].StartDate, 'm/d')# #TimeFormat(eventRecords[i].StartTime, 'h:mm tt')#
		</cfif>
	<cfelse> 
	#TimeFormat(eventRecords[i].StartTime, 'h:mm tt')#
	</cfif>
	<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate>
		<cfif eventRecords[i].StartDate neq thisDay>
		End #DateFormat(eventRecords[i].EndDate, "m/d")#
			<cfif len(trim(eventRecords[i].EndTime))> 
				#TimeFormat(eventRecords[i].EndTime, 'h:mm tt')#
			</cfif>
		</cfif>
	</cfif>
	<cfelse>
	all day event
	</cfif>
	</div>
	<cfset variables.tooltipHeader = DateFormat(eventRecords[i].StartDate,  "mmmm") & " " & Day(eventRecords[i].StartDate) />
	<cfif len(trim(eventRecords[i].StartTime))>
		<cfset variables.tooltipHeader = variables.tooltipHeader & "&nbsp;&nbsp;&nbsp;" & TimeFormat(eventRecords[i].StartTime, 'h:mm tt') />
	</cfif>
	<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate>
		<cfset variables.tooltipHeader = variables.tooltipHeader & "&nbsp;&nbsp;-&nbsp;&nbsp;" & DateFormat(attributes.linkDate,  "mmmm") & " " & DateFormat(eventRecords[i].EndDate, "d") />
	</cfif>
	<cfif len(trim(eventRecords[i].EndTime))>
		<cfset variables.tooltipHeader = variables.tooltipHeader & "&nbsp;&nbsp;&nbsp;" & TimeFormat(eventRecords[i].EndTime, 'h:mm tt') />
	</cfif>
	<cfset variables.tooltipHeader = variables.tooltipHeader & ":<br />" & Left(Trim(eventRecords[i].Title), attributes.TooltipSubLength) />
	<cfif len(eventRecords[i].Teaser)>
		<cfset variables.tooltipBody = Left(eventRecords[i].Teaser, attributes.maxDescriptionSize) />
		<cfif Len(eventRecords[i].Teaser) gt attributes.maxDescriptionSize>
			<cfset variables.tooltipBody = variables.tooltipBody & " ..." />
		</cfif>
	<cfelse>
		<cfset variables.tooltipBody = Left(eventRecords[i].Description, attributes.maxDescriptionSize) />
		<cfif Len(eventRecords[i].Description) gt attributes.maxDescriptionSize>
			<cfset variables.tooltipBody = variables.tooltipBody & " ..." />
		</cfif>
	</cfif>
	<div <cfif len(eventRecords[i].Teaser) OR len(eventRecords[i].Description)>title="header=[#HTMLEditFormat(variables.tooltipHeader)#] body=[#HTMLEditFormat(variables.tooltipBody)#] cssbody=[calendarTooltipSub] cssheader=[calendarTooltip]"</cfif> class="eventDisplay"<cfif application.KConfig.getUseCategoryColors() AND Len(Trim(eventRecords[i].CategoryBGColor))> style="background-color: ###eventRecords[i].CategoryBGColor#;"</cfif>>
	<a href="#attributes.calendarLinkPage#?#eventRecords[i].EventIDLabel#=#eventRecords[i].EventID#&amp;View=#attributes.View#&amp;linkDate=#UrlEncodedFormat(Attributes.linkDate)#<cfif len(attributes.urlAddString)>#attributes.urlAddString#</cfif>" class="eventDisplay"<cfif application.KConfig.getUseCategoryColors() AND Len(Trim(eventRecords[i].CategoryTextColor))> style="color: ###eventRecords[i].CategoryTextColor#;"</cfif>>#Trim(eventRecords[i].Title)#</a>
	</div>
	<div style="display:none;" class="vevent">
	<span class="dtstamp">#DateFormat(Now(), "yyyy-mm-dd")#T#TimeFormat(Now(), "HH:mm:ss")#</span>
	<span class="summary title">#Trim(eventRecords[i].Title)#</span>
	<a href="http://#cgi.server_name#/#attributes.calendarLinkPage#?#eventRecords[i].EventIDLabel#=#eventRecords[i].EventID#&amp;View=#attributes.View#&amp;linkDate=#UrlEncodedFormat(Attributes.linkDate)#<cfif len(attributes.urlAddString)>#attributes.urlAddString#</cfif>" class="url">Event Link</a>
	<div class="description">#eventRecords[i].Description#</div>
	<span class="dtstart" title="#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#<cfif Len(Trim(eventRecords[i].StartTime))>T#TimeFormat(eventRecords[i].StartTime, "HH:mm:ss")#</cfif>">#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#<cfif Len(Trim(eventRecords[i].StartTime))>T#TimeFormat(eventRecords[i].StartTime, "HH:mm:ss")#</cfif></span>
	<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate AND eventRecords[i].StartTime neq eventRecords[i].EndTime><span class="dtend" title="<cfif eventRecords[i].EndDate neq eventRecords[i].StartDate>#DateFormat(eventRecords[i].EndDate, "yyyy-mm-dd")#<cfelse>#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#</cfif><cfif Len(Trim(eventRecords[i].EndTime))>T#TimeFormat(eventRecords[i].EndTime, "HH:mm:ss")#</cfif>"><cfif eventRecords[i].EndDate neq eventRecords[i].StartDate>#DateFormat(eventRecords[i].EndDate, "yyyy-mm-dd")#<cfelse>#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#</cfif><cfif Len(Trim(eventRecords[i].EndTime))>T#TimeFormat(eventRecords[i].EndTime, "HH:mm:ss")#</cfif></span></cfif>
	</div>
	</cfif>
	</cfif>
	</div>
	</cfoutput>
	</cfloop>
	</td>
	</cfloop>
</tr>							
</table>
<p></p>
</td>
</tr>
</table> 